package com.yeyks.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

/**
 * @author shuai
 */
@Slf4j
@Component
public class MyRunner implements ApplicationRunner {
    @Autowired
    private ConfigurableApplicationContext context;

    @Value("${server.port}")
    private String port;
    @Value("${server.servlet.context-path:}")
    private String contextPath;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (context.isActive()) {
            InetAddress address = InetAddress.getLocalHost();
            String url = String.format("http://%s:%s", address.getHostAddress(), port);
            if (contextPath != null)
                url += contextPath;
            log.info("web后台启动完毕，swagger地址：{}", url + "/swagger-ui.html");
        }
    }
}
